let VSHADER_SOURCE = `
    attribute vec4 a_Position;
    attribute float a_PointSize;
    void main(){
        gl_Position = a_Position;
        gl_PointSize = a_PointSize;
    }
`;
let FSHADER_SOURCE = `
    precision mediump float;
    uniform vec4 u_FragColor;
    void main(){
        gl_FragColor = vec4(1.0,0.8,0.8,1.0);
        // gl_FragColor = u_FragColor;
    }
`;
function main() {
    let canvas = document.getElementById('webgl');
    let gl = getWebGLContext(canvas);
    let init = !initShaders(gl, VSHADER_SOURCE, FSHADER_SOURCE)
    if (init) {
        return console.error('error');
    }
    let n = initVertexBuffers(gl);
    if (n < 0) {
        console.error('Error!');
        return;
    }
    gl.clearColor(0.0, 0.8, 0.8, 1.0);
    gl.clear(gl.COLOR_BUFFER_BIT);
    gl.drawArrays(gl.POINTS, 0, n);
}
function initVertexBuffers(gl) {
    let vartices = new Float32Array([
        0.0, 0.5,
        -0.5, -0.5,
        0.5, -0.5
    ])
    let sizes = new Float32Array([
        10.0, 20.0, 30.0
    ])
    let n = 3;
    //创建缓冲区
    let vertexBuffer = gl.createBuffer();
    let sizeBuffer = gl.createBuffer();
    if (!vertexBuffer) {
        console.error('vertexBuffer Error!');
        return -1;
    }
    gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
    gl.bufferData(gl.ARRAY_BUFFER, vartices, gl.STATIC_DRAW);
    let a_Position = gl.getAttribLocation(gl.program, 'a_Position');
    gl.vertexAttribPointer(a_Position, 2, gl.FLOAT, false, 0, 0);
    gl.enableVertexAttribArray(a_Position);

    gl.bindBuffer(gl.ARRAY_BUFFER, sizeBuffer);
    gl.bufferData(gl.ARRAY_BUFFER, sizes, gl.STATIC_DRAW);
    let a_PointSize = gl.getAttribLocation(gl.program, 'a_PointSize');
    gl.vertexAttribPointer(a_PointSize, 1, gl.FLOAT, false, 0, 0);
    gl.enableVertexAttribArray(a_PointSize);
    return n;
}